﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using STT.Business;
using STT.Entities;
using STT.Layer.Connection;
using System.Data;

namespace STT.Admin.UserControls
{
    public partial class ucTimKiemKhoaHoc : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Methods.Lop(ref ddLopHoc);    
        }

        protected void lbXuatDuLieu_Click(object sender, EventArgs e)
        {
          
        }

        void LoadData()
        {
            DataTable dt = BTbKhoaHoc.SelectCoursesBySearch(new ETbKhoaHoc
            {
                MaKhoaHoc = txtMaKhoaHoc.Text.Trim() != "" ? int.Parse(txtMaKhoaHoc.Text.Trim()) : -1,
                TenKhoaHoc = txtTenKhoaHoc.Text.Trim(),
                DiaDiemHoc = txtPhongHoc.Text.Trim(),
                ThoiGianBatDau = txtThoiGianBatDau.Text.Trim() == "" ? default(DateTime) : DateTime.Parse(txtThoiGianBatDau.Text),
                ThoiGianKetThuc = txtThoiGianKetThuc.Text.Trim() == "" ? default(DateTime) : DateTime.Parse(txtThoiGianKetThuc.Text),
            }, txtTenGiangVien.Text.Trim(),
           txtSoHocVien.Text.Trim() != "" ? int.Parse(txtSoHocVien.Text.Trim()) : -1,
           ddLopHoc.SelectedValue == "-1" ? "" : ddLopHoc.SelectedValue,
           txtNamHoc.Text,Session["TenDN"].ToString()
           );
            
            rpvKhoaHoc.Visible = true;
            rpvKhoaHoc.LocalReport.ReportPath = "RDLC\\TKKhoaHoc.rdlc";
            rpvKhoaHoc.LocalReport.DataSources.Clear();
            rpvKhoaHoc.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
          
        }

        protected void btTimKiem_Click(object sender, EventArgs e)
        {
            LoadData();
         
            //ScriptManager.RegisterClientScriptBlock(this, GetType(), "Thông báo!", "<script>alert('" + txtThoiGianKetThuc.Text + "')</script>", false);
        }

       

        protected void gvKhoaHoc_DataBound(object sender, EventArgs e)
        {
            GridView gv1 = (GridView)sender;
            gv1.ShowFooter = true;

            for (int i = gv1.Columns.Count - 1; i >= 1; i += -1)
            {
                gv1.FooterRow.Cells.RemoveAt(i);

            }

            gv1.FooterRow.Cells[0].ColumnSpan = gv1.Columns.Count;

            gv1.FooterRow.Cells[0].HorizontalAlign =

            HorizontalAlign.Center;
            gv1.FooterRow.Cells[0].Text =

            "Tổng số kết quả tìm thấy: " + gv1.Rows.Count.ToString();
            gv1.FooterRow.Cells[0].Font.Bold = true; 
        }
    }
}